// 技能是收妖且目标不可收，禁止
const Swda_CatchCanSelect_Window_BattleEnemy_isCurrentItemEnabled = Window_BattleEnemy.prototype.isCurrentItemEnabled;
Window_BattleEnemy.prototype.isCurrentItemEnabled = function(){
	const enemy = this.enemy();
	const action = BattleManager.inputtingAction();
	if(!!action && !!enemy && action.isCatchItem())
		return enemy.isStateAddable(action.catchState());
	else
		return Swda_CatchCanSelect_Window_BattleEnemy_isCurrentItemEnabled.call(this);
};

// 这个函数控制血条的绘制 返回true才会画血条
const Swda_CatchCanSelect_Game_Battler_isSelected = Game_Battler.prototype.isSelected;
Game_Battler.prototype.isSelected = function(){
	const action = BattleManager.inputtingAction();
	if($gameParty.inBattle() && !!action && !!action.item()){
		if(action.isCatchItem()) //如果是收化技能，禁收即禁选
			return this.isStateAddable(action.catchState()) 
				&& Swda_CatchCanSelect_Game_Battler_isSelected.call(this);
	}
	return Swda_CatchCanSelect_Game_Battler_isSelected.call(this);
};

//鼠标指针移动的目标是否可以捕捉，true光标正常
BattleManager.isMouseOverEnemyCanCatch = function(){
	const enemies = $gameTroop.aliveMembers();
	const action = this.inputtingAction();
	if(!action)
		return true;
	else if(!action.isCatchItem())
		return true;

	for(let i = 0; i < enemies.length; i++){
		let enemy = enemies[i];
		//鼠标重合在角色上，允许捕捉就正常
		if(!!enemy && Window_BattleEnemy.prototype.isMouseOverEnemy.call(null, enemy))
			return enemy.isStateAddable(action.catchState());
	}
	return true;
};

BattleManager.setForbiddenTargetMouseCursor = function(){
	CP.CustomMouseCursor.setMouseCursorType("forbidden");
};

//战斗流程监听，战斗流程执行中，敌方宣目标时刷新鼠标
const Swda_CatchCanSelect_Scene_Battle_updateProcess = Scene_Battle.prototype.updateBattleProcess;
Scene_Battle.prototype.updateBattleProcess = function(){
	Swda_CatchCanSelect_Scene_Battle_updateProcess.call(this);
	if(BattleManager.isInputting() && this._enemyWindow.active){
		const canCatch = BattleManager.isMouseOverEnemyCanCatch();
		if(canCatch	&& CP.CustomMouseCursor.cursorType() !== CP.CustomMouseCursor.TARGET_CURSOR)
			CP.CustomMouseCursor.setMouseCursorType(CP.CustomMouseCursor.TARGET_CURSOR);
		else if(!canCatch && CP.CustomMouseCursor.cursorType() === CP.CustomMouseCursor.TARGET_CURSOR)
			BattleManager.setForbiddenTargetMouseCursor();
	}
};